package net.pinnoocle.playshoppc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.group.AddGroup;
import net.pinnoocle.playdao.entity.group.UpdateGroup;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playdao.entity.shopPc.coupon.CouponListPageVo;
import net.pinnoocle.playdao.entity.shopPc.coupon.CouponListSearchParams;
import net.pinnoocle.playdao.entity.shopPc.group.SaveGroupParams;
import net.pinnoocle.playdao.entity.shopPc.group.ShopGroupListPageVo;
import net.pinnoocle.playdao.entity.shopPc.group.ShopGroupListSearchParams;
import net.pinnoocle.playdao.entity.shopPc.group.ShopPcGroupDetailVo;
import net.pinnoocle.playdao.entity.web.group.GroupDetailVo;
import net.pinnoocle.playdao.entity.web.group.GroupListSearchParams;
import net.pinnoocle.playservice.service.impl.GroupServiceImpl;
import net.pinnoocle.playservice.service.impl.MasterServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ye
 * @Description
 * @create 2021-10-26 17:53
 */

@RestController
@RequestMapping("/group")
@Api(tags = "组局管理")
public class GroupController {

    @Autowired
    GroupServiceImpl groupService;
    @Autowired
    MasterServiceImpl masterService;

    @GetMapping("shopGroupList")
    @ApiOperation("店铺组局列表")
    public BaseResult<PageModel<ShopGroupListPageVo>> shopGroupList(ShopGroupListSearchParams params){
        return new BaseResult<PageModel<ShopGroupListPageVo>>().ok(groupService.shopGroupList(params));
    }

    @PostMapping("createGroup")
    @ApiOperation("发起组局")
    public BaseResult<String> createGroup(@Validated({AddGroup.class}) @RequestBody SaveGroupParams params){
        boolean result = groupService.saveGroup(params);
        if(result){
            return new BaseResult<String>().success("组局成功");
        }
        return new BaseResult<String>().error("组局失败");
    }

    @GetMapping("groupDetail")
    @ApiOperation("组局详情")
    public BaseResult<GroupDetailVo> groupDetail(@RequestParam("groupId") String groupId){
        return new BaseResult<GroupDetailVo>().ok(groupService.groupDetailForShopPc(groupId));
    }

    @PostMapping("renewGroup")
    @ApiOperation("重新发起组局")
    public BaseResult<String> renewGroup(@Validated({UpdateGroup.class}) @RequestBody SaveGroupParams params){
        boolean result = groupService.updateGroup(params);
        if(result){
            return new BaseResult<String>().success("重新发起组局成功");
        }
        return new BaseResult<String>().error("重新发起组局失败");
    }

    @GetMapping("deleteGroup")
    @ApiOperation("移除组局")
    public BaseResult<String> deleteGroup(@RequestParam("groupId") String groupId){
        boolean result = groupService.deleteGroup(groupId);
        if(result){
            return new BaseResult<String>().success("移除组局成功");
        }
        return new BaseResult<String>().error("移除组局失败");
    }

    @GetMapping("masterStartGroup")
    @ApiOperation("开始组局")
    public BaseResult<String> masterStartGroup(@RequestParam("groupId") String groupId){
        boolean result = masterService.startGroup(groupId,"");
        if(result){
            return new BaseResult<String>().success("开局成功");
        }
        return new BaseResult<String>().error("开局失败");
    }

    @GetMapping("overGroup")
    @ApiOperation("结束组局")
    public BaseResult<String> masterOverGroup(@RequestParam("groupId") String groupId){
        boolean result = masterService.overGroup(groupId,"");
        if(result){
            return new BaseResult<String>().success("结束组局成功");
        }
        return new BaseResult<String>().error("结束组局失败");
    }

    @GetMapping("lastGroup")
    @ApiOperation("最新未支付完的组局")
    public BaseResult<GroupDetailVo> lastGroup(){
        return new BaseResult<GroupDetailVo>().ok(groupService.lastGroup());
    }
}
